//
//  CalendarViewCell.swift
//  DaGlass
//
//  Created by 李然 on 2023/4/6.
//

import UIKit
import MoyoungLib

class CalendarViewCell: CollectionViewCell {
    
    override func makeUI() {
        super.makeUI()
        
        self.contentView.addSubview(circleView)
        circleView.snp.makeConstraints { make in
            make.edges.equalTo(UIEdgeInsets(top: 4, left: 4, bottom: 4, right: 4))
        }
        
        let stackView = StackView()
        stackView.axis = .vertical
        stackView.contentMode = .center
        stackView.spacing = 2
        stackView.addArrangedSubview(self.dayLabel)
        
        self.contentView.addSubview(stackView)
        stackView.snp.makeConstraints { make in
            make.centerX.equalToSuperview()
            make.centerY.equalToSuperview().offset(2)
        }
    }
    
    func set(calendarType: CalendarType, model: CalendarModel) {
        
        dayLabel.isHidden = false
        circleView.isHidden = false

        switch model.type {
        case .future:
            dayLabel.textColor = R.color.common_23_text_second()
            dayLabel.text = "\(model.day)"
            circleView.backgroundColor = .clear
        case .empty:
            dayLabel.text = ""
            dayLabel.isHidden = true
            circleView.isHidden = true
        case .normal:
            dayLabel.text = "\(model.day)"
            if model.isSelected {
                circleView.backgroundColor = R.color.common_27_main_color()
                dayLabel.textColor = R.color.common_8_text()
            } else {
                circleView.backgroundColor = UIColor.clear
                dayLabel.textColor = R.color.common_3_text()
            }
        }
    }
    
    override func layoutSubviews() {
        super.layoutSubviews()
        self.circleView.layer.cornerRadius = self.circleView.bounds.width/2
    }
    
    lazy var circleView: View = {
        let circleView = View()
        circleView.backgroundColor = R.color.common_27_main_color()
        return circleView
    }()

    lazy var dayLabel: Label = {
        let dayLabel = Label()
        dayLabel.textAlignment = .center
        dayLabel.font = Fonts.systemFont(ofSize: 18)
        return dayLabel
    }()
}
